package com.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class Demo01Servlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        //1.获取Servlet别名 servlet-name
        System.out.println(config.getServletName());
        //2.获取初始化参数
        System.out.println(config.getInitParameter("password"));
        //3.获取 ServletContext 对象
        ServletContext servletContext = config.getServletContext();
        //3.1 存值
        servletContext.setAttribute("username","root");

        //3.2 取值
//        Object username = servletContext.getAttribute("username");
//        System.out.println(username);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
